/**
 * @param {number} K
 * @return {number}
 */
const smallestRepunitDivByK = function (K) {
  if (K % 2 === 0 || K % 5 === 0) return -1
  let r = 0
  for (let N = 1; N <= K; ++N) {
    r = (r * 10 + 1) % K
    if (r == 0) return N
  }
  return -1
}
